<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="要求名称" prop="requirementName">
      <el-input v-model="dataForm.requirementName" placeholder="要求名称"></el-input>
    </el-form-item>
    <el-form-item label="要求内容">
      <el-input v-model="dataForm.requirementContent" placeholder="要求内容"></el-input>
    </el-form-item>
<!--    <el-form-item label="影响价格" prop="influencePrice">-->
<!--      <el-input v-model="dataForm.influencePrice" placeholder="影响价格"></el-input>-->
<!--    </el-form-item>-->
    <el-form-item label="状态" prop="status">
			<el-radio v-model="dataForm.status" label="1">正常</el-radio>
			<el-radio v-model="dataForm.status" label="2">停用</el-radio>
    </el-form-item>
<!--    <el-form-item label="是否快捷要求" prop="quickRequirement">-->
<!--			<el-radio v-model="dataForm.quickRequirement" label="1">是</el-radio>-->
<!--			<el-radio v-model="dataForm.quickRequirement" label="2">否</el-radio>-->
<!--    </el-form-item>-->
    <el-form-item label="备注">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          requirementId: 0,
          requirementName: '',
          requirementContent: '',
          sellerId: '',
          influencePrice: '',
          status: '1',
          quickRequirement: '1',
          remark: ''
        },
        dataRule: {
          requirementName: [
            { required: true, message: '要求名称不能为空', trigger: 'blur' }
          ],
          requirementContent: [
            { required: true, message: '要求内容不能为空', trigger: 'blur' }
          ],
          sellerId: [
            { required: true, message: '租户不能为空', trigger: 'blur' }
          ],
          influencePrice: [
            { required: true, message: '影响价格不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态(1正常2停用)不能为空', trigger: 'blur' }
          ],
          quickRequirement: [
            { required: true, message: '是否快捷要求(1是2否)不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.requirementId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.requirementId) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstorerequirement/info/${this.dataForm.requirementId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.requirementName = data.tStoreRequirement.requirementName
                this.dataForm.requirementContent = data.tStoreRequirement.requirementContent
                this.dataForm.sellerId = data.tStoreRequirement.sellerId
                this.dataForm.influencePrice = data.tStoreRequirement.influencePrice
                this.dataForm.status = data.tStoreRequirement.status.toString()
                this.dataForm.quickRequirement = data.tStoreRequirement.quickRequirement.toString()
                this.dataForm.remark = data.tStoreRequirement.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
				this.disabledSubmit = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstorerequirement/${!this.dataForm.requirementId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'requirementId': this.dataForm.requirementId || undefined,
                'requirementName': this.dataForm.requirementName,
                'requirementContent': this.dataForm.requirementContent,
                'sellerId': this.dataForm.sellerId,
                'influencePrice': this.dataForm.influencePrice,
                'status': this.dataForm.status,
                'quickRequirement': this.dataForm.quickRequirement,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
										this.disabledSubmit = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }else {
            this.disabledSubmit = false
          }
        })
      }
    }
  }
</script>
